package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.po.LearningLesson;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author yp
 * @since 2024-07-19
 */
@RestController
@RequestMapping("/lessons")
@Api(tags = "课表相关的接口")
@RequiredArgsConstructor
public class LearningLessonController {
    private final ILearningLessonService lessonService;

    @GetMapping("/page")
    @ApiOperation("分页查询我的课表")
    public PageDTO<LearningLessonVO> queryMyLessons(@Validated PageQuery query) {

        return lessonService.queeyMylessons(query);
    }

    @GetMapping("/now")
    @ApiOperation("查询当前用户最近学习的课程")
    public LearningLessonVO queryCurrent() {
        return lessonService.querycurrent();
    }

    @GetMapping("/{courseId}")
    @ApiOperation("根据课程id查询课程信息")
    public LearningLessonVO queryByCourseId(@PathVariable("courseId") Long courseId) {
        return lessonService.queryByCourseId(courseId);
    }

    /**
     * 校验当前用户是否可以学习当前课程
     *
     * @param courseId 课程id
     * @return true：课程有效，false：课程无效，不能学习
     */
    @GetMapping("/{courseId}/valid")
    @ApiOperation("根据课程id查询课表id")
    Long isLessonValid(@PathVariable("courseId") Long courseId) {

        return lessonService.judgecoureseisLessonValid(courseId);
    }

    @DeleteMapping("/{courseId}")
    @ApiOperation("根据课程id删除课表中的课程")
    void DeleteLearningLesson(@PathVariable("courseId") Long courseId) {
        lessonService.deletebyCouresId(courseId);
    }

    /**
     * 统计课程学习人数
     *
     * @param courseId 课程id
     * @return 学习人数
     */
    @GetMapping("/{courseId}/count")
    @ApiOperation("统计课程学习的人数")
    Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId) {
        return lessonService.countPeople(courseId);
    }


    /**
     * 创建我的学习方法
     *
     * @param dto
     */
    @PostMapping("/plans")
    @ApiOperation("创建我的学习计划")
    public void createLessonPlan(@RequestBody LearningPlanDTO dto) {
        lessonService.createLessonPlan(dto);
    }

    @GetMapping("plans")
    @ApiOperation("查询我的学习计划")
    public LearningPlanPageVO queryMyPlan(PageQuery pageQuery) {
        return lessonService.queeyMypalns(pageQuery);
    }
}
